<?php

abstract class TransactionCentral_CurlTransaction
{
    protected static function curlTransaction($transUrl, $action, Array $urlParams)
	{	    
	    $urlString = '';
	    
		foreach($urlParams as $param=>$value)
		{
			$urlString .= "&" . $param . "=" . $value;
		}
	
		$ch = curl_init();
					
		$headers[] = 'Content-Type: application/x-www-form-urlencoded';
						
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_URL, $transUrl . $action);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $urlString);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
							
		try {
			$reply_xml = curl_exec($ch);
			
		} catch (Exception $e) {
			echo "<pre>" . $e->getMessage() . "</pre>"; die;
		}
		
		/*
		 * Return simplexml object. If more complexity is needed then a 
		 * result object (i.e. TransactionResult class) might be needed.
		 */
		return simplexml_load_string($reply_xml);
	}
}